import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from "unplugin-element-plus/vite";
import path from "path";
// https://vitejs.dev/config/

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver({
        importStyle: "sass",
      })],
    }),
    Components({
      resolvers: [ElementPlusResolver({
        importStyle: "sass",
      })],
    }),
    ElementPlus({
      useSource: true,
      defaultLocale: "zh-tw",
    }),
  ],
  resolve: {
    alias: {
      "~/": `${path.resolve(__dirname, "src")}/`,
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "~/theme/style.scss" as *;`,
      },
    },
  },
  server: {
    proxy: {
      //代理配置
      "/fnji": {
        target: "https://website.fnji.com", //目标域名
        changeOrigin: true,
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            // 在代理请求中添加自定义 header ，伪装本次请求
            // host:website.fnji.com
            // origin:https://www.fnji.com
            // referer:https://www.fnji.com/
            proxyReq.setHeader("host", "website.fnji.com");
            proxyReq.setHeader("origin", "https://www.fnji.com");
            proxyReq.setHeader("Referer", "https://www.fnji.com/");
          });
        },
        rewrite: (path) => path.replace(/^\/fnji/, ""),
      },
      "/tyapi": {
        target: "https://tyapi.71360.com", //目标域名
        changeOrigin: true,
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            proxyReq.setHeader("host", "tyapi.71360.com");
            proxyReq.setHeader("origin", "http://www.ccsinter.com");
            proxyReq.setHeader("Referer", "http://www.ccsinter.com/");
          });
        },
        rewrite: (path) => path.replace(/^\/tyapi/, ""),
      },
    },
  },
})